<?php
namespace app\api\controller\m2979\auto;

use app\member\model\User;

use think\Db;
use service\ApiReturn;
use app\api\controller\Base;


class Freehuiyuan extends Base {
                
/**
 *  查询会员
 *@param  String[字符串]  cheng  昵称
 *@param  String[字符串]  kaiguan  开关
 *@create_time  2023-08-22 17:31:38
 */ 
public function get_huiyuan($data = [], $user = [])
{
    $user = User::addUser();
    $headLang  = request()->header('lang');
    $where = [];
    $this->updateApply();
    $order = 'freehuiyuan.aid desc';
	if (!empty($data['sort_field'])) {
		$order = 'freehuiyuan.'.$data['sort_field'].' '.$data['sort_type'];
	}

	$this->saveFileTo();
    $where[] = ['freehuiyuan.is_del', '=', 0]; 
 	if (!empty($data['cheng'])) {
		$where[] = ['freehuiyuan.cheng', '=', $data['cheng']]; 
 	}
	if (isset($data['kaiguan'])) {
		$where[] = ['freehuiyuan.kaiguan', '=', $data['kaiguan']]; 
 	}

    $select_info = array (
); 
	$dataList = Db::table('lb_free_huiyuan')
		->alias('freehuiyuan')
		->field("freehuiyuan.cheng,freehuiyuan.kaiguan,freehuiyuan.create_time")
		->where($where)
		->order($order)
		->select();
	foreach ($dataList as &$infodataList){
			$infodataList['create_time'] = $infodataList['create_time'];
	}

    if($dataList){
        return ApiReturn::r(1, $dataList, '请求成功');
    }else{
        return ApiReturn::r(1, [], '暂无数据');
    }
}
            
/**
 *  查询会员
 *@param  String[字符串]  cheng  昵称
 *@param  String[字符串]  kaiguan  开关
 *@create_time  2023-08-22 18:01:25
 */ 
public function get_huiyuan2($data = [], $user = [])
{
    $headLang  = request()->header('lang');
    $where = [];
  
    $order = 'freehuiyuan.aid desc';
	if (!empty($data['sort_field'])) {
		$order = 'freehuiyuan.'.$data['sort_field'].' '.$data['sort_type'];
	}

    $where[] = ['freehuiyuan.is_del', '=', 0]; 
 	if (!empty($data['cheng'])) {
		$where[] = ['freehuiyuan.cheng', '=', $data['cheng']]; 
 	}
	if (isset($data['kaiguan'])) {
		$where[] = ['freehuiyuan.kaiguan', '=', $data['kaiguan']]; 
 	}

    $select_info = array (
); 
	$dataList = Db::table('lb_free_huiyuan')
		->alias('freehuiyuan')
		->field("freehuiyuan.cheng,freehuiyuan.kaiguan,freehuiyuan.create_time")
		->where($where)
		->order($order)
		->select();
	foreach ($dataList as &$infodataList){
			$infodataList['create_time'] = $infodataList['create_time'];
	}

    if($dataList){
        return ApiReturn::r(1, $dataList, '请求成功');
    }else{
        return ApiReturn::r(1, [], '暂无数据');
    }
}
                
/**
 *  操作会员
 *@param  String[字符串]  cheng  昵称
 *@create_time  2023-08-24 10:36:31
 */ 
public function set_huiyuan($data = [], $user = [])
{
    $return_data = [];
 
     		//查询会员
		$order = 'freehuiyuan.create_time desc';
		$where = [];
		$where[] = ['freehuiyuan.is_del', '=', 0]; 
 		if (isset($data[''])) {
		$where[] = ['freehuiyuan.cheng', '=', $data['']]; 
 		}
		$query_0 = Db::table('lb_free_huiyuan')
		->alias('freehuiyuan')
		->where($where)
		->order($order)
		->value('cheng');
		$query_0['cheng'] = $query_0;
        
     

    return ApiReturn::r(1, $return_data, '请求成功');
}
            
/**
 *  查询会员
 *@create_time  2023-08-26 16:35:13
 */ 
public function get_huiyuan_add_user($data = [], $user = [])
{
    $headLang  = request()->header('lang');
    $where = [];
  
    $order = 'freehuiyuan.aid desc';
	if (!empty($data['sort_field'])) {
		$order = 'freehuiyuan.'.$data['sort_field'].' '.$data['sort_type'];
	}

    $where[] = ['freehuiyuan.is_del', '=', 0]; 
 
    $select_info = array (
  'shenfen' => 
  array (
    1 => '普通用户',
    2 => '会员',
  ),
); 
	$dataList = Db::table('lb_free_huiyuan')
		->alias('freehuiyuan')
		->leftjoin('lb_free_fenlei freefenlei', 'freefenlei.aid = freehuiyuan.freefenlei_id')
		->field("freehuiyuan.cheng,freehuiyuan.kaiguan,freehuiyuan.shipin,freehuiyuan.touxiang,freefenlei.dianhua as freefenlei_dianhua,dianhua_2 as dianhua_2,freehuiyuan.shuzi,freehuiyuan.shenfen,freehuiyuan.create_time")
		->where($where)
		->order($order)
		->select();
	foreach ($dataList as &$infodataList){
			$infodataList['shipin']  = [get_file_url($infodataList['shipin'])];
			$infodataList['touxiang']  = get_file_url($infodataList['touxiang']);
			$infodataList['shenfen_name'] = $select_info['shenfen']["{$infodataList['shenfen']}"] ?? '';
			$infodataList['create_time'] = $infodataList['create_time'];
	}

    if($dataList){
        return ApiReturn::r(1, $dataList, '请求成功');
    }else{
        return ApiReturn::r(1, [], '暂无数据');
    }
}
            
/**
 *  查询会员
 *@create_time  2023-09-04 14:36:02
 */ 
public function get_huiyuan123($data = [], $user = [])
{

    $headLang  = request()->header('lang');
    $where = [];
  
    $order = 'freehuiyuan.aid desc';
	if (!empty($data['sort_field'])) {
		$order = 'freehuiyuan.'.$data['sort_field'].' '.$data['sort_type'];
	}

    $where[] = ['freehuiyuan.is_del', '=', 0]; 
 
    $select_info = array (
); 
	$dataList = Db::table('lb_free_huiyuan')
		->alias('freehuiyuan')
		->field("freehuiyuan.cheng")
		->where($where)
		->order($order)
		->select();
	//字段多语言替换
	if ($headLang) {
		$dataList = get_api_datas_lang('lb_free_huiyuan', $dataList);
	}

    if($dataList){
        return ApiReturn::r(1, $dataList, '123');
    }else{
        return ApiReturn::r(1, [], '暂无数据');
    }
}
            
/**
 *  查询会员0916
 *@param  String[字符串]  cheng  昵称
 *@create_time  2023-09-16 14:36:02
 */ 
public function get_huiyuan_0916($data = [], $user = [])
{
    $headLang  = request()->header('lang');
    $where = [];
  
    $order = 'freehuiyuan.aid desc';
	if (!empty($data['sort_field'])) {
		$order = 'freehuiyuan.'.$data['sort_field'].' '.$data['sort_type'];
	}

    $where[] = ['freehuiyuan.is_del', '=', 0]; 
 	if (!empty($data['cheng'])) {
		$where[] = ['freehuiyuan.cheng', '=', $data['cheng']]; 
 	}

    $select_info = array (
  'shenfen' => 
  array (
    1 => '普通用户',
    2 => '会员',
  ),
); 
	$dataList = Db::table('lb_free_huiyuan')
		->alias('freehuiyuan')
		->field("freehuiyuan.aid,freehuiyuan.cheng,freehuiyuan.shoujihaoma,freehuiyuan.shenfen,freehuiyuan.create_id,freehuiyuan.create_time")
		->where($where)
		->order($order)
		->select();
	foreach ($dataList as &$infodataList){
			$infodataList['shenfen_name'] = $select_info['shenfen']["{$infodataList['shenfen']}"] ?? '';
			$infodataList['create_time'] = $infodataList['create_time']? date('Y-m-d H:i:s', $infodataList['create_time']): '';
	}

    if($dataList){
        return ApiReturn::r(1, $dataList, '请求成功');
    }else{
        return ApiReturn::r(1, [], '暂无数据');
    }
}
            
/**
 *  查询会员
 *@param  Integer[整数]  aid  ID
 *@param  String[字符串]  cheng  昵称
 *@param  Date[日期]  create_time  创建时间
 *@create_time  2023-09-16 14:56:11
 */ 
public function get_huiyuan0999($data = [], $user = [])
{
    $headLang  = request()->header('lang');
    $where = [];
  
    $order = 'freehuiyuan.aid desc';
	if (!empty($data['sort_field'])) {
		$order = 'freehuiyuan.'.$data['sort_field'].' '.$data['sort_type'];
	}

    $where[] = ['freehuiyuan.is_del', '=', 0]; 
 
    $select_info = array (
); 
	$dataList = Db::table('lb_free_huiyuan')
		->alias('freehuiyuan')
		->field("freehuiyuan.aid,freehuiyuan.cheng,freehuiyuan.create_time")
		->where($where)
		->order($order)
		->select();
	foreach ($dataList as &$infodataList){
			$infodataList['create_time'] = $infodataList['create_time']? date('Y-m-d H:i:s', $infodataList['create_time']): '';
	}

    if($dataList){
        return ApiReturn::r(1, $dataList, '请求成功');
    }else{
        return ApiReturn::r(1, [], '暂无数据');
    }
}
            
/**
 *  查询会员
 *@param  Integer[整数]  aid  ID
 *@param  String[字符串]  cheng  昵称
 *@param  Integer[整数]  shuzi  数字
 *@create_time  2023-09-21 12:00:11
 */ 
public function get_huiyuan001($data = [], $user = [])
{
    $headLang  = request()->header('lang');
    $where = [];
  
    $order = 'freehuiyuan.aid desc';
	if (!empty($data['sort_field'])) {
		$order = 'freehuiyuan.'.$data['sort_field'].' '.$data['sort_type'];
	}

    $where[] = ['freehuiyuan.is_del', '=', 0]; 
 
    $select_info = array (
); 
	$dataList = Db::table('lb_free_huiyuan')
		->alias('freehuiyuan')
		->field("freehuiyuan.aid,freehuiyuan.cheng,freehuiyuan.kaiguan,freehuiyuan.create_time")
		->where($where)
		->order($order)
		->select();
	foreach ($dataList as &$infodataList){
			$infodataList['create_time'] = $infodataList['create_time']? date('Y-m-d H:i:s', $infodataList['create_time']): '';
	}
	//字段多语言替换
	if ($headLang) {
		$dataList = get_api_datas_lang('lb_free_huiyuan', $dataList);
	}

    if($dataList){
        return ApiReturn::r(1, $dataList, '请求成功');
    }else{
        return ApiReturn::r(1, [], '暂无数据');
    }
}
                
/**
 *  
 *@param  String[字符串]  cheng  昵称
 *@create_time  2023-09-16 15:59:34
 */ 
public function test_api($data = [], $user = [])
{
    $return_data = [];
 
     		//入参判断
		if (!($data['cheng'] == $data['cheng'])) {
			throw new \Exception('错误',-1);
		}
		//查询
		$order = 'freehuiyuan.create_time desc';
		$where = [];
		$where[] = ['freehuiyuan.is_del', '=', 0]; 
 		if (isset($data['cheng'])) {
		$where[] = ['freehuiyuan.create_time', '=', $data['cheng']]; 
 		}
		$query_1 = Db::table('lb_free_huiyuan')
		->alias('freehuiyuan')
		->where($where)
		->order($order)
		->find();
		if (!($query_1)) {
			throw new \Exception('错误',-1);
		}

        
     

    return ApiReturn::r(1, $return_data, '请求成功');
}
            
/**
 *  查询会员
 *@create_time  2023-10-06 16:36:35
 */ 
public function get_huiyuan12($data = [], $user = [])
{
    $url = member_config_com('web_site_domain') . '/automatic/m2979.freehuiyuan/sidebar?&layer=1&id=86';
    $image = member_config_com('web_site_domain').addons_action('Qrcode/Qrcode/generate',[$url]);
    echo $image;die;
    $headLang  = request()->header('lang');
    $where = [];
  
    $order = 'freehuiyuan.aid desc';
	if (!empty($data['sort_field'])) {
		$order = 'freehuiyuan.'.$data['sort_field'].' '.$data['sort_type'];
	}

    $where[] = ['freehuiyuan.is_del', '=', 0]; 
 	if (!empty($data['shenfen'])) {
		$value_arr = explode(',',$data['shenfen']); 
		$value_arr = array_filter($value_arr); 
		$where[] = ['freehuiyuan.shenfen', 'in', $value_arr ]; 
 	}

    $select_info = array (
  'shenfen' => 
  array (
    1 => '普通用户',
    2 => '会员',
  ),
); 
	$dataList = Db::table('lb_free_huiyuan')
		->alias('freehuiyuan')
		->leftjoin('lb_free_fenlei freefenlei', 'freefenlei.aid = freehuiyuan.freefenlei_id')
		->leftjoin('lb_free_yonghu freeyonghu', 'freeyonghu.aid = freehuiyuan.freeyonghu_id')
		->field("freehuiyuan.aid,freehuiyuan.kaiguan,freeyonghu.mingzi as freeyonghu_mingzi,freefenlei.fenlei as freefenlei_fenlei,freehuiyuan.baifenbi,freehuiyuan.duoshenfen,freehuiyuan.shenfen,freehuiyuan.create_id,freehuiyuan.create_time")
		->where($where)
		->order($order)
		->select();
	foreach ($dataList as &$infodataList){
			$infodataList['shenfen_name'] = $select_info['shenfen']["{$infodataList['shenfen']}"] ?? '';
			$infodataList['create_time'] = $infodataList['create_time']? date('Y-m-d H:i:s', $infodataList['create_time']): '';
	}

    if($dataList){
        return ApiReturn::r(1, $dataList, '请求成功');
    }else{
        return ApiReturn::r(1, [], '暂无数据');
    }
}

}